package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/14 14:56
 */
public class HWBJJ22 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] strs = scanner.nextLine().split(",");

        List<Node> list = new ArrayList<>();
        Map<Integer,StringBuffer> map = new TreeMap<>();
        for (int i = 0; i < strs.length; i+=2) {

           int count = Integer.parseInt(strs[i+1]);

           //默认第一行
            int row = 1;
            //判断当前属于哪一个子集
            for (int j = list.size()-1; j >=0 ; j--) {
                //
                Node node = list.get(j);
                if (node.child > 0) {
                    node.child--;
                    row = node.row+1;
                    break;
                }
            }
            list.add(new Node(strs[i],row,count));
            map.put(row,map.getOrDefault(row,new StringBuffer()).append(strs[i]).append(" "));
        }
        System.out.println(map.size());
        for (Integer i : map.keySet()) {
            System.out.println(map.get(i).substring(0,map.get(i).length()-1));
        }

    }
    static class Node{
        String content;

        int row;

        int child;

        public Node(String content, int row, int child) {
            this.content = content;
            this.row = row;
            this.child = child;
        }
    }
}
